/*
Code used to create summary statistics and results tables in Aisbett & Barbanente (2018) 
"THE IMPACT OF LARGE SCALE FOREIGN LAND ACQUISITIONS ON RURAL HOUSEHOLDS: EVIDENCE FROM ETHIOPIA"
*/

* ?? You will need to enter valid paths to the dataset location and results directory on your computer

*global dataset "?Your path?\AisbettBarbanente2018data.dta"
*global resultdir "?Your path to desired results output folder?" 

global depvars1 "FieldArea LandVal TotalExp FoodExp"
global depvars2 "AgWkHr NonAgWk WgWkHr cert cred totalAid"
* Note in code below D'var' indicates first difference, Dln'var' indicates first difference of log, decrease'var' is dummy indicating value of 'var' decreased between waves


*******************************************************************
********  Summary Stats  ********
*******************************************************************
* Dep vars
global sumvar1 "FieldArea LandVal TotalExp FoodExpWk"
global sumvar2 "AgWkHrs NonAgWkHrs WgWkHrs Cert Cred totalAid"
* Control / matching vars
global sumvar3 "dist_market hhold_size af_bio_12 everschool srtm_5_15"

use "$dataset", clear
cd "$resultdir"
log using "meantests.smcl", replace
set more off
drop if srtm_5==6 | srtm_5==9 | srtm_5==12 | srtm_5==14 | year==2013
tabstat $sumvar1 $sumvar2 $sumvar3 if BenGum==0 & year==2011, statistics(mean n) by(Gambel)
tabstat $sumvar1 $sumvar2 $sumvar3 if Gambel==0 & year==2011, statistics(mean n) by(BenGum)
forvalues dv=1/3{
foreach var of global sumvar`dv'{
forvalues tr=1/2{
if (`tr'==1) {
display "`var'"
display "Treatment=Gambella"
ttest `var', by(Gambel)
}
if (`tr'==2) {
display "`var'"
display "Treatment=BenGum"
ttest `var', by(BenGum)
}
}
}
}
log close

*******************************************************************
*************************  Main results  **************************
*******************************************************************
cd "$resultdir"
local loop
local tittext= "Diff-in-diff regressions. (1) & (2) Simple. (3) & (4) with CEM weights. (5) & (6) with CEM weights and regression controls."
set more off
forvalues dv=1/2{
local loop=0
foreach var of global depvars`dv'{
local loop=`loop'+1
forvalues tr=1/2{
use "$dataset", clear
drop if srtm_5==6 | srtm_5==9 | srtm_5==12 | srtm_5==14
if (`tr'==1) {
display "Treatment=Gambella"
drop if srtm_5==3 | srtm_5==7
keep if BenGum==0 & year==2013
cem hhold_size2011 (#0) af_bio_12 (2) everschool2011 (#0) srtm_5_15 (#0) SC2011 (#0), treatment(Gambel)
gen treatvar=Gambel
set more off
}
if (`tr'==2) {
display "Treatment=BenGum"
drop if srtm_5==2
keep if Gambel==0 & year==2013
cem hhold_size2011 (#0) af_bio_12 (2) everschool2011 (#0) srtm_5_15 (#0) SC2011 (#0), treatment(BenGum)
gen treatvar=BenGum
set more off
}
label var treatvar "`var'"
if (`dv'==1) {
reg D`var' treatvar, robust
est store D`var'treat`tr'
reg Dln`var' treatvar, robust
est store Dln`var'treat`tr'
reg D`var' treatvar [aweight= cem_weights] , robust
est store D`var'treat`tr'CEM
reg Dln`var' treatvar [aweight= cem_weights] , robust
est store Dln`var'treat`tr'CEM
reg D`var' treatvar af_bio_12 dist_market [aweight= cem_weights] , robust
est store D`var'treat`tr'D
reg Dln`var' treatvar af_bio_12 dist_market [aweight= cem_weights] , robust
est store Dln`var'treat`tr'D
}
if (`dv'==2) {
reg D`var' treatvar, robust
est store D`var'treat`tr'
logit `var'decreased treatvar, robust
est store dec`var'treat`tr'
reg D`var' treatvar [aweight= cem_weights] , robust
est store D`var'treat`tr'CEM
logit `var'decreased treatvar [iweight= cem_weights] , robust
est store dec`var'treat`tr'CEM
reg D`var' treatvar af_bio_12 dist_market [aweight= cem_weights] , robust
est store D`var'treat`tr'D
logit `var'decreased treatvar af_bio_12 dist_market [iweight= cem_weights] , robust
est store dec`var'treat`tr'D
}
}
cd "$resultdir"
di `loop'
if (`dv'==1) {
if (`loop'==1) {
esttab D`var'treat1 Dln`var'treat1 D`var'treat1CEM Dln`var'treat1CEM D`var'treat1D Dln`var'treat1D using "Gambel.txt", title(`tittext') mtitles("Level" "Log" "Level" "Log" "Level" "Log") label se star(* 0.1 ** 0.05  *** 0.01) drop(af_bio_12 dist_market) tab noconstant nolines nonotes noobs nogap replace
esttab D`var'treat2 Dln`var'treat2 D`var'treat2CEM Dln`var'treat2CEM D`var'treat2D Dln`var'treat2D using "BenGum.txt", title(`tittext') mtitles("Level" "Log" "Level" "Log" "Level" "Log") label se star(* 0.1 ** 0.05  *** 0.01) drop(af_bio_12 dist_market) tab noconstant nolines nonotes noobs nogap replace
}
else {
esttab D`var'treat1 Dln`var'treat1 D`var'treat1CEM Dln`var'treat1CEM D`var'treat1D Dln`var'treat1D using "Gambel.txt", label nogap se star(* 0.1 ** 0.05  *** 0.01) drop(af_bio_12 dist_market) tab noconstant nolines nonotes noobs nomtitles nonumbers append
esttab D`var'treat2 Dln`var'treat2 D`var'treat2CEM Dln`var'treat2CEM D`var'treat2D Dln`var'treat2D using "BenGum.txt", label nogap se star(* 0.1 ** 0.05  *** 0.01) drop(af_bio_12 dist_market) tab noconstant nolines nonotes noobs nomtitles nonumbers append
}
}
if (`dv'==2) {
if (`loop'==1) {
esttab D`var'treat1 dec`var'treat1 D`var'treat1CEM dec`var'treat1CEM D`var'treat1D dec`var'treat1D using "Gambel.txt", title(`tittext') mtitles("Level" "Binary Indicator" "Level" "Binary Indicator" "Level" "Binary Indicator") label se star(* 0.1 ** 0.05  *** 0.01)  drop(af_bio_12 dist_market) tab noconstant nolines nonotes noobs nogap append
esttab D`var'treat2 dec`var'treat2 D`var'treat2CEM dec`var'treat2CEM D`var'treat2D dec`var'treat2D using "BenGum.txt", title(`tittext') mtitles("Level" "Binary Indicator" "Level" "Binary Indicator" "Level" "Binary Indicator") label se star(* 0.1 ** 0.05  *** 0.01)  drop(af_bio_12 dist_market) tab noconstant nolines nonotes noobs nogap append
}
else {
esttab D`var'treat1 dec`var'treat1 D`var'treat1CEM dec`var'treat1CEM D`var'treat1D dec`var'treat1D using "Gambel.txt", label nogap se star(* 0.1 ** 0.05  *** 0.01)  drop(af_bio_12 dist_market) tab noconstant nolines nonotes noobs nomtitles nonumbers append
esttab D`var'treat2 dec`var'treat2 D`var'treat2CEM dec`var'treat2CEM D`var'treat2D dec`var'treat2D using "BenGum.txt", label nogap se star(* 0.1 ** 0.05  *** 0.01)  drop(af_bio_12 dist_market) tab noconstant nolines nonotes noobs nomtitles nonumbers append
}
}
}
}
*

*******************************************************************
***** Robustness to standard errors clustered at region level *****
*******************************************************************
cd "$resultdir"
local loop
local tittext= "Diff-in-diff regressions. (1) & (2) Simple. (3) & (4) with CEM weights. (5) & (6) with CEM weights and regression controls."
set more off
forvalues dv=1/2{
local loop=0
foreach var of global depvars`dv'{
local loop=`loop'+1
forvalues tr=1/2{
use "$dataset", clear
drop if srtm_5==6 | srtm_5==9 | srtm_5==12 | srtm_5==14
if (`tr'==1) {
display "Treatment=Gambella"
drop if srtm_5==3 | srtm_5==7
keep if BenGum==0 & year==2013
cem hhold_size2011 (#0) af_bio_12 (2) everschool2011 (#0) srtm_5_15 (#0) SC2011 (#0), treatment(Gambel)
gen treatvar=Gambel
set more off
}
if (`tr'==2) {
display "Treatment=BenGum"
drop if srtm_5==2
keep if Gambel==0 & year==2013
cem hhold_size2011 (#0) af_bio_12 (2) everschool2011 (#0) srtm_5_15 (#0) SC2011 (#0), treatment(BenGum)
gen treatvar=BenGum
set more off
}
label var treatvar "`var'"
if (`dv'==1) {
reg D`var' treatvar, cluster(region)
est store D`var'treat`tr'
reg Dln`var' treatvar, cluster(region)
est store Dln`var'treat`tr'
reg D`var' treatvar [aweight= cem_weights] , cluster(region)
est store D`var'treat`tr'CEM
reg Dln`var' treatvar [aweight= cem_weights] , cluster(region)
est store Dln`var'treat`tr'CEM
reg D`var' treatvar af_bio_12 dist_market [aweight= cem_weights] , cluster(region)
est store D`var'treat`tr'D
reg Dln`var' treatvar af_bio_12 dist_market [aweight= cem_weights] , cluster(region)
est store Dln`var'treat`tr'D
}
if (`dv'==2) {
reg D`var' treatvar, cluster(region)
est store D`var'treat`tr'
logit `var'decreased treatvar, cluster(region)
est store dec`var'treat`tr'
reg D`var' treatvar [aweight= cem_weights] , cluster(region)
est store D`var'treat`tr'CEM
logit `var'decreased treatvar [iweight= cem_weights] , cluster(region)
est store dec`var'treat`tr'CEM
reg D`var' treatvar af_bio_12 dist_market [aweight= cem_weights] , cluster(region)
est store D`var'treat`tr'D
logit `var'decreased treatvar af_bio_12 dist_market [iweight= cem_weights] , cluster(region)
est store dec`var'treat`tr'D
}
}
cd "$resultdir"
di `loop'
if (`dv'==1) {
if (`loop'==1) {
esttab D`var'treat1 Dln`var'treat1 D`var'treat1CEM Dln`var'treat1CEM D`var'treat1D Dln`var'treat1D using "Gambel_cluster.txt", title(`tittext') mtitles("Level" "Log" "Level" "Log" "Level" "Log") label se star(* 0.1 ** 0.05  *** 0.01) drop(af_bio_12 dist_market) tab noconstant nolines nonotes   nogap replace
esttab D`var'treat2 Dln`var'treat2 D`var'treat2CEM Dln`var'treat2CEM D`var'treat2D Dln`var'treat2D using "BenGum_cluster.txt", title(`tittext') mtitles("Level" "Log" "Level" "Log" "Level" "Log") label se star(* 0.1 ** 0.05  *** 0.01) drop(af_bio_12 dist_market) tab noconstant nolines nonotes   nogap replace
}
else {
esttab D`var'treat1 Dln`var'treat1 D`var'treat1CEM Dln`var'treat1CEM D`var'treat1D Dln`var'treat1D using "Gambel_cluster.txt", label nogap se star(* 0.1 ** 0.05  *** 0.01) drop(af_bio_12 dist_market) tab noconstant nolines nonotes nomtitles nonumbers append
esttab D`var'treat2 Dln`var'treat2 D`var'treat2CEM Dln`var'treat2CEM D`var'treat2D Dln`var'treat2D using "BenGum_cluster.txt", label nogap se star(* 0.1 ** 0.05  *** 0.01) drop(af_bio_12 dist_market) tab noconstant nolines nonotes nomtitles nonumbers append
}
}
if (`dv'==2) {
if (`loop'==1) {
esttab D`var'treat1 dec`var'treat1 D`var'treat1CEM dec`var'treat1CEM D`var'treat1D dec`var'treat1D using "Gambel_cluster.txt", title(`tittext') mtitles("Level" "Binary Indicator" "Level" "Binary Indicator" "Level" "Binary Indicator") label se star(* 0.1 ** 0.05  *** 0.01)  drop(af_bio_12 dist_market) tab noconstant nolines nonotes nogap append
esttab D`var'treat2 dec`var'treat2 D`var'treat2CEM dec`var'treat2CEM D`var'treat2D dec`var'treat2D using "BenGum_cluster.txt", title(`tittext') mtitles("Level" "Binary Indicator" "Level" "Binary Indicator" "Level" "Binary Indicator") label se star(* 0.1 ** 0.05  *** 0.01)  drop(af_bio_12 dist_market) tab noconstant nolines nonotes nogap append
}
else {
esttab D`var'treat1 dec`var'treat1 D`var'treat1CEM dec`var'treat1CEM D`var'treat1D dec`var'treat1D using "Gambel_cluster.txt", label nogap se star(* 0.1 ** 0.05  *** 0.01)  drop(af_bio_12 dist_market) tab noconstant nolines nonotes nomtitles nonumbers append
esttab D`var'treat2 dec`var'treat2 D`var'treat2CEM dec`var'treat2CEM D`var'treat2D dec`var'treat2D using "BenGum_cluster.txt", label nogap se star(* 0.1 ** 0.05  *** 0.01)  drop(af_bio_12 dist_market) tab noconstant nolines nonotes nomtitles nonumbers append
}
}
}
}
